using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

using Read.Models;
using Read.Services;
using Read.Utility;

namespace Read.Web.Admin
{
    public class AjaxController : Controller
    {
        /// <summary>
        /// 获取后台菜单
        /// </summary>
        /// <returns></returns>
        [Area("Admin")]
        public IActionResult GetMenu()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return Json(new ResultData<string>() { Result = false, Code = -1, Message = "未登录" });
            }
            else
            {
                var role = User.FindFirst(ClaimTypes.Role).Value;
                var menu = new NodeService();
                
                ResultMenuModel menulist = menu.getMenu(role.ToInt32());  //JsonConvert.SerializeObject(adminlist);
                return Json(menulist.children);
            }
        }
    }
}